package com.lg.happyfarmer.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.lg.happyfarmer.R;
import com.lg.happyfarmer.base.BaseActivity;
import com.lg.happyfarmer.base.BaseUtil;
import com.lg.happyfarmer.snackbar.BaseTransientBottomBar;
import com.lg.happyfarmer.snackbar.TopSnackBar;
import com.lg.happyfarmer.untils.UserUtils;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 忘记密码1
 * Created by Torres on 2018/3/31 0031.
 */

public class ForgetPwd0Activity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.ib_back)
    ImageButton ib_back;
    @Bind(R.id.btn_test)
    Button btn_test;
    @Bind(R.id.ed_pwd)
    EditText ed_pwd;
    @Bind(R.id.iv_tip)
    ImageView iv_tip;
    @Bind(R.id.ll_all)
    LinearLayout ll_all;
    private int status=0;//1 正确 0 错误
    private String temp;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_forgetpwd0);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
        BaseUtil.startLayoutAnim(mContext,ll_all);
    }

    @Override
    protected void callBeforeDataBack(HemaNetTask netTask) {
        super.callBeforeDataBack(netTask);
    }

    @Override
    protected void callAfterDataBack(HemaNetTask netTask) {
        super.callAfterDataBack(netTask);
    }

    @Override
    protected void callBackForServerSuccess(HemaNetTask netTask, HemaBaseResult baseResult) {
        super.callBackForServerSuccess(netTask, baseResult);
    }

    @Override
    protected void callBackForServerFailed(HemaNetTask netTask, HemaBaseResult baseResult) {
        super.callBackForServerFailed(netTask, baseResult);
    }

    @Override
    protected void callBackForGetDataFailed(HemaNetTask netTask, int failedType) {
        super.callBackForGetDataFailed(netTask, failedType);
    }

    @Override
    protected void findView() {

        super.findView();
    }

    @Override
    protected void getExras() {
        super.getExras();
    }

    @Override
    protected void setListener() {
        super.setListener();
        btn_test.setOnClickListener(this);
        ib_back.setOnClickListener(this);
        iv_tip.setOnClickListener(this);
        ed_pwd.addTextChangedListener(new TextWatcher() {

            private boolean isDelete;
            @Override
            public void onTextChanged(CharSequence s, int cursorPosition, int before, int count) {
                ed_pwd.setOnKeyListener(new View.OnKeyListener() {

                    @Override
                    public boolean onKey(View v, int keyCode, KeyEvent event) {
                        if (keyCode == KeyEvent.KEYCODE_DEL) {
                            isDelete = true;
                        }
                        return false;
                    }
                });
            }
            @Override
            public void afterTextChanged(Editable arg0) {
                temp=arg0.toString().replace(" ","");

//                XtomToastUtil.showLongToast(mContext,temp);
                if(temp.length()>=6){

                        btn_test.setEnabled(true);
                }else{
                    iv_tip.setVisibility(View.INVISIBLE);
                    btn_test.setEnabled(false);
                }

            }
            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1,int arg2, int arg3) {
            }
        });
    }

    @Override
    public void onClick(View view) {
        Intent it=null;
        switch (view.getId()) {
            case R.id.iv_tip:
                break;
            case R.id.ib_back:
                finish();
                break;
            case R.id.btn_test:
                it=new Intent(mContext,ForgetPwdActivity1.class);
                it.putExtra("pwd",ed_pwd.getText().toString().trim());
                startActivity(it);
                break;
        }
    }
}
